var env;
try {
    var resJson = __RESOURCE_MAP__;
    console.log("RequireJs ResMap Loading !!! ")
    env = "release";
} catch (d) {
    __uri = function (path) {
        var index = path.lastIndexOf(".");
        if (index > 0) {
            path = path.substr(0, index);

        }
        return path;
    }
    env = "dev";
}

var pathMaps = {
    zepto: __uri("libraries/zepto.min.js"),
    //测试
    localStorage: __uri("libraries/backbone-localstorage.js"),
    backbone: __uri("libraries/backbone-min.js"),
    underscore: __uri("libraries/underscore-min.js"),
    text: __uri("libraries/text.js"),
    etopscroll: __uri("libraries/etopscroll.js"),
    config: __uri("config/config.js"),
    wTools: __uri("libraries/wTools.js")
    ,area: __uri("libraries/area.js")
    ,cookie: __uri("libraries/zepto_cookie.js")
    ,validate: __uri("libraries/validate.js")
    //添加 antbridge
    ,antbridge: __uri("libraries/antbridge.min.js")
};

if (env === "release") {
    for (var key in resJson.res) {
        if (key.indexOf("view/") == 0 || key.indexOf("controllers/") == 0 || key.indexOf("config/") == 0 || key.indexOf("templates/") == 0) {
            var index = key.lastIndexOf(".");
            if (index !== -1) {
                var shortKey = key.substring(0, index);
                var ext = key.substring(index + 1, key.length);
                if (shortKey.indexOf("config/") == 0) {
                    shortKey = shortKey.substr(7, shortKey.length);
                    console.log("author: weiew,winston")
                }
                var url = resJson.res[key].uri;
                url = url.substring(0, url.indexOf(ext));
                pathMaps[shortKey] = url;
            }
        }
    }

    for (var key in pathMaps) {
        var url = pathMaps[key];
        var index = url.lastIndexOf(".");
        if (index > 0) {
            url = url.substr(0, index);
            pathMaps[key] = url;
        }
    }
}
require.config({
    baseUrl: "",
    paths: pathMaps,
    shim: {
        'backbone': {
            deps: ['underscore', 'zepto','cookie'],
            exports: 'Backbone'
        },
        'etopscroll': {
            deps: ['zepto']
        },
        'zepto': {
            exports: '$'
        },
        'underscore': {
            exports: '_'
        }
    }
});

require(["controllers/router"], function (router) {
        window.router = new router();
        Backbone.history.start();
    }
);